<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_reunion=new reunion();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["id"])){$_reunion->set_id($_POST["id"]);}
		if(isset($_POST["code_ue"])){$_reunion->set_code_ue($_POST["code_ue"]);}
		if(isset($_POST["date"])){$_reunion->set_date($_POST["date"]);}
		if(isset($_POST["lieu"])){$_reunion->set_lieu($_POST["lieu"]);}
		if(isset($_POST["concepteur"])){$_reunion->set_concepteur($_POST["concepteur"]);}
		if(isset($_POST["enseignant"])){$_reunion->set_enseignant($_POST["enseignant"]);}
		if(isset($_POST["objectif"])){$_reunion->set_objectif($_POST["objectif"]);}
		if(isset($_POST["observation"])){$_reunion->set_observation($_POST["observation"]);}
		$res=$_reunion->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["id"])){
		$_reunion->set_id($_POST["id"]);
		$res=$_reunion->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["id"])){$_reunion->set_id($_POST["id"]);}
		if(isset($_POST["code_ue"])){$_reunion->set_code_ue($_POST["code_ue"]);}
		if(isset($_POST["date"])){$_reunion->set_date($_POST["date"]);}
		if(isset($_POST["lieu"])){$_reunion->set_lieu($_POST["lieu"]);}
		if(isset($_POST["concepteur"])){$_reunion->set_concepteur($_POST["concepteur"]);}
		if(isset($_POST["enseignant"])){$_reunion->set_enseignant($_POST["enseignant"]);}
		if(isset($_POST["objectif"])){$_reunion->set_objectif($_POST["objectif"]);}
		if(isset($_POST["observation"])){$_reunion->set_observation($_POST["observation"]);}
		$res=$_reunion->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["id"]) && !empty($_POST["id"])){
		$constraint.=" AND id='".$_POST["id"]."'";
	}

	if(isset($_POST["code_ue"]) && !empty($_POST["code_ue"])){
		$constraint.=" AND code_ue='".$_POST["code_ue"]."'";
	}

	if(isset($_POST["date"]) && !empty($_POST["date"])){
		$constraint.=" AND date='".$_POST["date"]."'";
	}

	if(isset($_POST["lieu"]) && !empty($_POST["lieu"])){
		$constraint.=" AND lieu='".$_POST["lieu"]."'";
	}

	if(isset($_POST["concepteur"]) && !empty($_POST["concepteur"])){
		$constraint.=" AND concepteur='".$_POST["concepteur"]."'";
	}

	if(isset($_POST["enseignant"]) && !empty($_POST["enseignant"])){
		$constraint.=" AND enseignant='".$_POST["enseignant"]."'";
	}

	if(isset($_POST["objectif"]) && !empty($_POST["objectif"])){
		$constraint.=" AND objectif='".$_POST["objectif"]."'";
	}

	if(isset($_POST["observation"]) && !empty($_POST["observation"])){
		$constraint.=" AND observation='".$_POST["observation"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_reunion->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_reunion->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>